package coder.nav.controller;

import coder.nav.utils.CheckMobileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "页面路由")
@Controller
public class ModelAndViewController {

    @ApiOperation("登录")
    @GetMapping("/login")
    public ModelAndView login(ModelAndView modelAndView) {
        modelAndView.setViewName("login");
        return modelAndView;
    }

    @ApiOperation("个人设置")
    @GetMapping("/setting")
    public ModelAndView setting(ModelAndView modelAndView, HttpServletRequest request) {
        boolean isMobile = CheckMobileUtils.check(request.getHeader("User-Agent"));
        if(isMobile) {
            modelAndView.setViewName("h5/setting");
            return modelAndView;
        }
        modelAndView.setViewName("pc/setting");
        return modelAndView;
    }

    @ApiOperation("记账本")
    @GetMapping("/cash")
    public ModelAndView cash(ModelAndView modelAndView, HttpServletRequest request) {
        boolean isMobile = CheckMobileUtils.check(request.getHeader("User-Agent"));
        if(isMobile) {
            modelAndView.setViewName("h5/cash");
            return modelAndView;
        }
        modelAndView.setViewName("pc/cash");
        return modelAndView;
    }

    @ApiOperation("记事本")
    @GetMapping("/memo")
    public ModelAndView memo(ModelAndView modelAndView, HttpServletRequest request) {
        boolean isMobile = CheckMobileUtils.check(request.getHeader("User-Agent"));
        if(isMobile) {
            modelAndView.setViewName("h5/memo");
            return modelAndView;
        }
        modelAndView.setViewName("pc/memo");
        return modelAndView;
    }

    @ApiOperation("动态页面")
    @GetMapping("/page")
    public ModelAndView page(ModelAndView modelAndView, HttpServletRequest request) {
        boolean isMobile = CheckMobileUtils.check(request.getHeader("User-Agent"));
        if(isMobile) {
            modelAndView.setViewName("h5/page");
            return modelAndView;
        }
        modelAndView.setViewName("pc/page");
        return modelAndView;
    }

    @ApiOperation("定时任务")
    @GetMapping("/task")
    public ModelAndView task(ModelAndView modelAndView, HttpServletRequest request) {
        boolean isMobile = CheckMobileUtils.check(request.getHeader("User-Agent"));
        if(isMobile) {
            modelAndView.setViewName("h5/task");
            return modelAndView;
        }
        modelAndView.setViewName("pc/task");
        return modelAndView;
    }

    @ApiOperation("博客")
    @GetMapping("/blog")
    public ModelAndView blog() {
        return new ModelAndView(new RedirectView("https://blog.csdn.net/weixin_47600880"));
    }

    @ApiOperation("码云")
    @GetMapping("/gitee")
    public ModelAndView gitee() {
        return new ModelAndView(new RedirectView("https://gitee.com/bosen-once"));
    }

}
